package top.zackyoung.druid.simple.config;

import lombok.extern.slf4j.Slf4j;

/**
 * @author ZackYoung
 * @version 1.0
 * @date 2021/9/28
 */
@Slf4j
public class DynamicDataSourceSwitcher {
    public static final String MASTER = "master";
    public static final String SLAVE1 = "slave1";
    public static final ThreadLocal<String> contextHolder = new ThreadLocal<>();

    public static void setDataSource(String name) {
        log.info("-------- 设置数据源数据源为 ：{} ", name);
        contextHolder.set(name);
    }

    public static String getDataSource() {
        return contextHolder.get();
    }

    public static void cleanDataSource() {
        contextHolder.remove();
    }
}
